
//
//  Contact.m
//  04-集合2-DIctionary
//
//  Created by dllo on 16/7/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Contact.h"

@implementation Contact
- (instancetype)initWithName:(NSString *)name
                         sex:(NSString *)sex
                 phoneNumber:(NSString *)phoneNumber
                      adress:(NSString *)adress
                         age:(NSInteger)age {
    self = [super init];
    if (self) {
        // 初始化方法中,不要使用set方法赋值
        _name = name;
        _sex = sex;
        _phoneNumber = phoneNumber;
        _adress = adress;
        _age = age;
        _groupName = [[name substringToIndex:1] capitalizedString];
    }
    return self;
}
+ (instancetype)contactWithName:(NSString *)name
                            sex:(NSString *)sex
                    phoneNumber:(NSString *)phoneNumber
                         adress:(NSString *)adress
                            age:(NSInteger)age {
    return [[Contact alloc] initWithName:name
                                     sex:sex
                             phoneNumber:phoneNumber
                                  adress:adress
                                     age:age];
}
- (NSString *)description{
    return [NSString stringWithFormat:@"name= %@ sex= %@ phoneNumber= %@ adress= %@ age= %ld groupname= %@", self.name, self.sex, self.phoneNumber, self.adress, self.age, self.groupName];

}
- (void)showContact {
    NSLog(@"姓名:%@ 性别:%@ 电话号码:%@ 地址:%@ 年龄:%ld", self.name, self.sex, self.phoneNumber, self.adress, self.age);
}



@end
